# -*- coding: UTF-8 -*-
class Parent:
    parentAttr = 100;

    def __init__(self):
        print("调用父类构造函数！");

    def parentMethod(self):
        print("调用父类方法！");

    def setAttr(self, attr):
        Parent.parentAttr = attr;

    def getAttr(self):
        print("父类属性：" + Parent.parentAttr);


class Child(Parent):
    def __init__(self):
        print("调用子类构造方法！");

    def childMethod(self):
        print("调用子类方法childMethod！");

    def parentMethod(self):
        print("调用父类方法parentMethod！");


c = Child();
c.childMethod();
c.parentMethod();
c.setAttr("120");
c.getAttr();
c.parentMethod();


class Vector:
    # 双下划线表示私有属性
    __a = 10;

    def __init__(self, a, b):
        self.a = a;
        self.b = b;

    def __str__(self):
        return "Vector is (%d,%d)" % (self.a, self.b);

    def __add__(self, other):
        return Vector(self.a + other.a, self.b + other.b);

    def __privateMethod(self):
        print("私有方法");


v1 = Vector(2, 10);
v2 = Vector(5, -2);

print("v1+v2:%d" % (v1 + v2));
